﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace Oxage.Common
{
	/// <summary>
	/// Handles conversion from color string to System.Windows.Media.Color instance.
	/// </summary>
	public class ColorConverter : IValueConverter
	{
		#region IValueConverter members
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			Brush brush = new SolidColorBrush(Colors.Transparent);
			if (value != null && value is int)
			{
				int v = (int)value;
				if (parameter is string && (string)parameter != null)
				{
					bool alt = v % 2 == 1;
					string[] colors = (parameter as string).Split('|');
					brush = Oxage.CNC.Helper.GetBrush(colors[alt ? 0 : 1]);
				}
			}
			return brush;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			return null;
		}
		#endregion
	}
}
